﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Web;
    using WMS6.Web.CommonMethodService2Ref;

    public class CommoneMethodService2ClientProxy : BasePage
    {
        public static CommoneMethodService2ClientProxy GetInstance()
        {
            return new CommoneMethodService2ClientProxy();
        }

        public List<InvPalletInfo> GetInvPalletByIDAndType(string docID, string docType)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string language = base.UserInfo.Preference.Lang;
            using (CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2"))
            {
                return client.GetInvPalletByIDAndType(docID, docType, pubParasInfo);
            }
        }

        public List<SysCode4DDL> GetSysCodeDataSource(string sourceFrom)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string language = base.UserInfo.Preference.Lang;
            List<SysCode4DDL> sysCode4DDLList = null;
            CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2");
            try
            {
                sysCode4DDLList = client.GetBaseInfoForDDLSource(sourceFrom, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return sysCode4DDLList;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertInvPallet(List<InvPalletInfo> invPalletListInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string language = base.UserInfo.Preference.Lang;
            using (CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2"))
            {
                return client.InsertInvPallet(invPalletListInfo, pubParasInfo);
            }
        }

        public string ReleasePrintControl(List<PrintControlInfo> printControlInfos)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2"))
            {
                return client.ReleasePrintControl(printControlInfos, pubParasInfo);
            }
        }

        public string SavePrintControl(List<PrintControlInfo> printControlInfos)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2"))
            {
                return client.SavePrintControl(printControlInfos, pubParasInfo);
            }
        }

        public int UpdateASNAndSOSingleField(string orderType, string orderID, string updatedField, string value)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            int result = 0;
            CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2");
            try
            {
                result = client.UpdateASNAndSOSingleField(orderType, orderID, updatedField, value, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public int UpdateDeclarations(string Type, string keyID, string ExternOrderID, string CoreReleaseID, string WorkOrder)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2"))
            {
                return client.UpdateDeclarations(Type, keyID, ExternOrderID, CoreReleaseID, WorkOrder, pubParasInfo);
            }
        }

        public int UpdateExternOrderID(string Type, string keyID, string ExternOrderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (CommonMethodService2Client client = new CommonMethodService2Client("WSHttpBinding_ICommonMethodService2"))
            {
                return client.UpdateExternOrderID(Type, keyID, ExternOrderID, pubParasInfo);
            }
        }
    }
}

